package com.example.springbootlearn.concurrent;

import java.util.concurrent.*;

/**
 * @author caiji Mr. Li
 * @date 2019/10/23 21:43
 */
public class SemaphoreTest {
    private static Semaphore semaphore = new Semaphore(2);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.submit(() -> {
            System.out.println(Thread.currentThread() + " over");
            try {
                semaphore.acquire();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

//        executorService.submit(() -> {
//            System.out.println(Thread.currentThread() + " over");
//            try {
//                semaphore.acquire();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        });
//
//        semaphore.release(2);
//        System.out.println("all child thread over!");
        executorService.shutdown();
    }
}

